#include <iostream>
#include <vector>
#include <pthread.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <unistd.h>

void* routine(void* args)
{
    std::string name = (char*)args;
    delete (char*)args;
    std::cout << "我是子线程" << name << std::endl;
    return nullptr;
}

int main()
{
    std::vector<pthread_t> threads;
    for(int i = 0; i < 10; i++)
    {
        pthread_t tid;
        char* info = new char[64];
        snprintf(info, 64, "thread:%d", i);
        int n = pthread_create(&tid, nullptr, routine, (void*)info);
        if(n == 0)
        {
            threads.push_back(tid);
        }
        else
            continue;
        sleep(1);
    }

    for(int i = 0; i < 10; i++)
    {
        pthread_join(threads[i], nullptr);
        std::cout << "成功等待线程" << (long long)threads[i] << std::endl;
        sleep(1);
    }

    return 0;
}